
#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>
#include <unistd.h>
#include <fcntl.h>

#include "ev_log.h"
#include "ev_util.h"

int EV_util_CreatePairFd(int aiPairFds[2])
{
    // pipe
    return socketpair(AF_UNIX, SOCK_STREAM, 0, aiPairFds);
}

int EV_util_SetNonblock(int iFd)
{
    if (fcntl(iFd, F_SETFL, O_NONBLOCK) == -1) 
    {
		LOG_ERROR("fcntl(%d, F_SETFL)", iFd);
		return -1;
	}

    return 0;
}

int EV_util_SetCloseonexec(int iFd)
{
    if (fcntl(iFd, F_SETFD, FD_CLOEXEC) == -1) 
    {
		LOG_ERROR("fcntl(%d, F_SETFD)", iFd);
		return -1;
	}
}